#include "Singularity.h"

Singularity::Singularity(float m, float r, float g)
{
	magnitude = m;
	radius = r;
	radiusSquared = r*r;
	gravConst = g;
	active = false;
}

void Singularity::affect(Entity *entity)
{
	Vec2d disp = this->pos - entity->pos;
	float r2 = disp*disp;
	if (r2 < radiusSquared)
	{
		disp.normalize();
		entity->accel = entity->accel + disp * ((gravConst * magnitude) / r2);
	}
}

void Singularity::activate()
{
	active = true;
}

void Singularity::deactivate()
{
	active = false;
}

bool Singularity::isActive()
{
	return active;
}

bool Singularity::withinRadius(Entity *entity)
{
	Vec2d disp = this->pos - entity->pos;
	float r2 = disp*disp;
	
	if (r2 <= (this->radius * this->radius))
		return true;

	return false;
}